package com.funmi.lizip.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.funmi.lizip.common.base.R;
import com.funmi.lizip.entity.DataQualityInspection;
import com.funmi.lizip.entity.dto.DataQualityInspection.DataQualityInspectionAddRequest;
import com.funmi.lizip.entity.dto.DataQualityInspection.DataQualityInspectionUpdateRequest;
import com.funmi.lizip.service.DataQualityInspectionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.List;

@Api(tags = "数据质检管理")
@RestController
@RequestMapping("/dataQualityInspection")
public class DataQualityInspectionController {

    @Autowired
    private DataQualityInspectionService dataQualityInspectionService;

    @ResponseStatus(HttpStatus.OK)
    @ApiOperation(value = "获取所有")
    @GetMapping("")
    public R get(){
        List<DataQualityInspection> list = dataQualityInspectionService.list();
        return R.success().data(list);
    }

    @ResponseStatus(HttpStatus.OK)
    @ApiOperation(value = "编辑")
    @PutMapping("")
    public R update(@RequestBody DataQualityInspectionUpdateRequest request){
        DataQualityInspection dataQualityInspection = new DataQualityInspection();
        BeanUtils.copyProperties(request, dataQualityInspection);
        QueryWrapper<DataQualityInspection> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("id",request.getId());
        boolean update = dataQualityInspectionService.update(dataQualityInspection, queryWrapper);
        if (update){
            return R.success().message("修改成功");
        }
        return R.fail().message("修改失败");
    }

    @ResponseStatus(HttpStatus.OK)
    @ApiOperation(value = "新增")
    @PostMapping("")
    public R add(@RequestBody DataQualityInspectionAddRequest request){
        DataQualityInspection dataQualityInspection = new DataQualityInspection();
        dataQualityInspection.setContent(request.getContent());
        boolean save = dataQualityInspectionService.save(dataQualityInspection);
        if (save) {
            return R.success().message("新增成功");
        }
        return R.fail().message("新增失败");
    }
}
